load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("//bazel:defs.bzl", "rust_bench")

package(default_visibility = ["//visibility:public"])

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/crypto/test_utils/canister_threshold_sigs",
    "//rs/crypto/test_utils/crypto_returning_ok",
    "//rs/limits",
    "//rs/test_utilities",
    "//rs/test_utilities/artifact_pool",
    "//rs/test_utilities/consensus",
    "//rs/test_utilities/logger",
    "//rs/test_utilities/registry",
    "//rs/test_utilities/time",
    "//rs/test_utilities/types",
    "@crate_index//:rand",
    "@crate_index//:slog-async",
    "@crate_index//:slog-term",
]

rust_library(
    name = "artifact_pool",
    srcs = glob(["src/**"]),
    crate_name = "ic_artifact_pool",
    version = "0.9.0",
    deps = [
        # Keep sorted.
        "//rs/config",
        "//rs/interfaces",
        "//rs/monitoring/logger",
        "//rs/monitoring/metrics",
        "//rs/protobuf",
        "//rs/sys",
        "//rs/types/types",
        "@crate_index//:bincode",
        "@crate_index//:byteorder",
        "@crate_index//:lmdb_rkv",
        "@crate_index//:lmdb_rkv_sys",
        "@crate_index//:nix",
        "@crate_index//:prometheus",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:slog",
        "@crate_index//:strum",
        "@crate_index//:tempfile",
    ] + select({
        "@platforms//os:osx": [
            "@crate_index//:rocksdb",
            "@crate_index//:slog-envlogger",  # needed by rocksdb implem
        ],
        "//conditions:default": [
        ],
    }),
)

rust_binary(
    name = "ic-consensus-pool-util",
    srcs = ["bin/consensus_pool_util.rs"],
    deps = [
        # Keep sorted.
        "//rs/config",
        "//rs/interfaces",
        "//rs/monitoring/logger",
        "//rs/monitoring/metrics",
        "//rs/protobuf",
        "//rs/sys",
        "//rs/types/types",
        "@crate_index//:bincode",
        "@crate_index//:byteorder",
        "@crate_index//:lmdb_rkv",
        "@crate_index//:lmdb_rkv_sys",
        "@crate_index//:nix",
        "@crate_index//:prometheus",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:slog",
        "@crate_index//:strum",
        "@crate_index//:tempfile",
    ] + select({
        "@platforms//os:osx": [
            "@crate_index//:rocksdb",
            "@crate_index//:slog-envlogger",  # needed by rocksdb implem
        ],
        "//conditions:default": [
        ],
    }) + [
        ":artifact_pool",
        "@crate_index//:clap",
        "@crate_index//:serde-bytes-repr",
        "@crate_index//:serde_json",
    ],
)

rust_test(
    name = "artifact_pool_test",
    crate = ":artifact_pool",
    deps = DEV_DEPENDENCIES,
)

BENCH_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:criterion",
]

rust_bench(
    name = "load_blocks_bench",
    testonly = True,
    srcs = ["benches/load_blocks.rs"],
    deps = [
        # Keep sorted.
        "//rs/config",
        "//rs/interfaces",
        "//rs/monitoring/logger",
        "//rs/monitoring/metrics",
        "//rs/protobuf",
        "//rs/sys",
        "//rs/types/types",
        "@crate_index//:bincode",
        "@crate_index//:byteorder",
        "@crate_index//:lmdb_rkv",
        "@crate_index//:lmdb_rkv_sys",
        "@crate_index//:nix",
        "@crate_index//:prometheus",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:slog",
        "@crate_index//:strum",
        "@crate_index//:tempfile",
    ] + select({
        "@platforms//os:osx": [
            "@crate_index//:rocksdb",
            "@crate_index//:slog-envlogger",  # needed by rocksdb implem
        ],
        "//conditions:default": [
        ],
    }) + DEV_DEPENDENCIES + BENCH_DEPENDENCIES + [":artifact_pool"],
)
